#!/usr/bin/python
# -*- coding: utf-8 -*-

from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText


def SendEamil(infos):
        mail_info = {
                "from": "***@139.com",
                "to": ['****@139.com', '****@139.com'],
                "hostname": "smtp.139.com",
                "username": "****@139.com",
                "password": "*****",
                "mail_subject": "游戏有关键字出现",
                "mail_text": '''内容详情:\n{}'''.format(infos),
                "mail_encoding": "utf-8"
        }
        #这里使用SMTP_SSL就是默认使用465端口
        smtp = SMTP_SSL(mail_info["hostname"], 465)
# debug模式
#       smtp.set_debuglevel(1)

        smtp.ehlo(mail_info["hostname"])
        smtp.login(mail_info["username"], mail_info["password"])

        msg = MIMEText(mail_info["mail_text"], "plain", mail_info["mail_encoding"])
        msg["Subject"] = Header(mail_info["mail_subject"], mail_info["mail_encoding"])
        msg["from"] = mail_info["from"]
        msg["to"] = ','.join(mail_info["to"])

        smtp.sendmail(mail_info["from"], mail_info["to"], msg.as_string())
        smtp.quit()
